package com.likersai.opon.scene.cultivation.controller;

import com.likersai.opon.pojo.bo.PageBO;
import com.likersai.opon.pojo.bo.ResponseBO;
import com.likersai.opon.scene.cultivation.entity.ConfigRealm;
import com.likersai.opon.scene.cultivation.service.ConfigRealmService;
import com.likersai.opon.scene.cultivation.service.req.MoveConfigRealmReq;
import com.likersai.opon.scene.cultivation.service.req.QueryConfigRealmReq;
import com.likersai.opon.scene.cultivation.service.req.SaveConfigRealmReq;
import com.likersai.opon.scene.cultivation.service.rsp.ConfigRealmRsp;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * (ConfigRealm)表控制层
 *
 * @author sun.ye
 * @since 2024-10-07 00:02:46
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/configRealm")
public class ConfigRealmController {

    private final ConfigRealmService configRealmService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/query/{id}")
    public ResponseBO<ConfigRealmRsp> query(@PathVariable("id") Long id) {
        return ResponseBO.getSuccess(configRealmService.query(id));
    }

    /**
     * 分页查询
     *
     * @param req 筛选条件
     * @return 查询结果
     */
    @PostMapping("/page")
    public ResponseBO<PageBO<ConfigRealmRsp>> page(@RequestBody QueryConfigRealmReq req) {
        PageBO<ConfigRealmRsp> result = configRealmService.page(req);
        return ResponseBO.getSuccess(result);
    }

    /**
     * 保存数据
     *
     * @param saveReq 请求入参
     * @return 保存结果
     */
    @PostMapping("/save")
    public ResponseBO<ConfigRealm> save(@RequestBody SaveConfigRealmReq saveReq) {
        return ResponseBO.getSuccess(configRealmService.save(saveReq));
    }

    /**
     * 删除数据
     *
     * @param moveReq 请求入参
     * @return 删除是否成功
     */
    @DeleteMapping("/move")
    public ResponseBO<Boolean> moveById(@RequestBody MoveConfigRealmReq moveReq) {
       return ResponseBO.getSuccess(configRealmService.moveById(moveReq));
    }
 
}

